﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">


    <Style x:Key="ToolBarOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Name="Bd"
          CornerRadius="0,3,3,0"
          Background="Transparent"
          SnapsToDevicePixels="true">
                        <Grid>
                            <Path Name="Arrow"
              Fill="Black"
              VerticalAlignment="Bottom"
              Margin="2,3"
              Data="M -0.5 3 L 5.5 3 L 2.5 6 Z"/>
                            <ContentPresenter/>
                        </Grid>
                    </Border>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



    <Style x:Key="{x:Type ToolBar}" TargetType="{x:Type ToolBar}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="FocusManager.IsFocusScope" Value="true"/>
        
        <!--<Setter Property="MinHeight" Value="50"/>-->        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToolBar}">                    
                    <Border x:Name="Border" Margin="0,0,0,0" Padding="0"  BorderThickness="0"  HorizontalAlignment="{TemplateBinding HorizontalAlignment}">
                        <DockPanel>
                            
                            <ToggleButton                                
                                x:Name="moreButton"
                                Visibility="Collapsed"
                                DockPanel.Dock="Right"
              IsEnabled="{TemplateBinding HasOverflowItems}"
              Style="{StaticResource ToolBarOverflowButtonStyle}"
              IsChecked="{Binding Path=IsOverflowOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
              ClickMode="Press">
                                <Popup x:Name="OverflowPopup"
                AllowsTransparency="true"
                Placement="Bottom"
                IsOpen="{Binding Path=IsOverflowOpen,RelativeSource={RelativeSource TemplatedParent}}"
                StaysOpen="false"
                Focusable="false"
                PopupAnimation="Slide">
                                    <Border x:Name="DropDownBorder"
                  Background="{TemplateBinding Background}"
                  BorderThickness="1"
                  BorderBrush="{TemplateBinding BorderBrush}">
                                        <ToolBarOverflowPanel x:Name="PART_ToolBarOverflowPanel"
                    Margin="2"
                    WrapWidth="200"
                    Focusable="true" 
                    FocusVisualStyle="{x:Null}"
                    KeyboardNavigation.TabNavigation="Cycle"
                    KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                    </Border>
                                </Popup>
                            </ToggleButton>


                            <ToolBarPanel
                                
                                x:Name="PART_ToolBarPanel"                                          
                                IsItemsHost="true"
                                
                                Margin="0,1,2,2"
                                
                                
                                TextBlock.Foreground="{StaticResource DarkTextBrush}"/>
                                
                        </DockPanel>
                       
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasOverflowItems" Value="true">
                            <Setter TargetName="moreButton" Property="Visibility" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
    </Style>

</ResourceDictionary>